package com.goldsign.pay.common.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.goldsign.pay.common.service.BaseService;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 
 * @author xiaoxianwen
 *
 * @param <T>
 */
@Service
public class BaseServiceImpl<T> implements BaseService<T> {

	@Override
	public T initParam(T t, HttpServletRequest request) {
		JSONObject json = (JSONObject)JSON.toJSON(t);
		String remoteAddr = request.getRemoteAddr();
		json.put("customer_ip", remoteAddr);
		json.put("ver", "1.0");
		json.put("req_time", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		return (T) JSONObject.toJavaObject(json, t.getClass());
	}

}
